23 #include "llvm/Config/llvm-config.h" 38 #define DEBUG_TYPE "coro-suspend-crossing" 44 class BlockToIndexMapping {
48 size_t size()
const {
return V.
size(); }
58 assert(
I != V.
end() && *
I == BB &&
"BasicBlockNumberng: Unknown block");
79 struct SuspendCrossingInfo {
80 BlockToIndexMapping Mapping;
91 BasicBlock *BB = Mapping.indexToBlock(&BD - &Block[0]);
96 return Block[Mapping.blockToIndex(BB)];
105 size_t const DefIndex = Mapping.blockToIndex(DefBB);
106 size_t const UseIndex = Mapping.blockToIndex(UseBB);
108 assert(Block[UseIndex].Consumes[DefIndex] &&
"use must consume def");
109 bool const Result = Block[UseIndex].Kills[DefIndex];
111 <<
" answer is " << Result <<
"\n");
115 bool isDefinitionAcrossSuspend(
BasicBlock *DefBB,
User *U)
const {
116 auto *
I = cast<Instruction>(U);
120 if (
auto *PN = dyn_cast<PHINode>(
I))
121 if (PN->getNumIncomingValues() > 1)
129 if (isa<CoroSuspendRetconInst>(
I)) {
131 assert(UseBB &&
"should have split coro.suspend into its own block");
134 return hasPathCrossingSuspendPoint(DefBB, UseBB);
137 bool isDefinitionAcrossSuspend(
Argument &A,
User *U)
const {
147 if (isa<AnyCoroSuspendInst>(I)) {
149 assert(DefBB &&
"should have split coro.suspend into its own block");
152 return isDefinitionAcrossSuspend(DefBB, U);
157 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 160 dbgs() << Label <<
":";
161 for (
size_t I = 0,
N = BV.
size();
I <
N; ++
I)
163 dbgs() <<
" " << Mapping.indexToBlock(I)->getName();
168 for (
size_t I = 0,
N = Block.size();
I <
N; ++
I) {
171 dump(
" Consumes", Block[
I].Consumes);
172 dump(
" Kills", Block[
I].Kills);
180 const size_t N = Mapping.size();
184 for (
size_t I = 0;
I <
N; ++
I) {
186 B.Consumes.resize(N);
195 getBlockData(CE->getParent()).End =
true;
203 auto &
B = getBlockData(SuspendBlock);
205 B.Kills |=
B.Consumes;
208 markSuspendBlock(CSI);
209 if (
auto *Save = CSI->getCoroSave())
210 markSuspendBlock(Save);
223 for (
size_t I = 0;
I <
N; ++
I) {
227 auto SuccNo = Mapping.blockToIndex(
SI);
231 auto &S = Block[SuccNo];
232 auto SavedConsumes = S.Consumes;
233 auto SavedKills = S.Kills;
236 S.Consumes |=
B.Consumes;
242 S.Kills |=
B.Consumes;
247 S.Kills |= S.Consumes;
257 S.Kills.reset(SuccNo);
261 Changed |= (S.Kills != SavedKills) || (S.Consumes != SavedConsumes);
263 if (S.Kills != SavedKills) {
269 if (S.Consumes != SavedConsumes) {
280 #undef DEBUG_TYPE // "coro-suspend-crossing" 281 #define DEBUG_TYPE "coro-frame" 306 unsigned fieldIndex()
const {
307 assert(FieldNo != InvalidFieldIndex &&
"Accessing unassigned field");
310 void setFieldIndex(
unsigned FieldNumber) {
311 assert(FieldNo == InvalidFieldIndex &&
"Reassigning field number");
312 FieldNo = FieldNumber;
323 dbgs() <<
"------------- " << Title <<
"--------------\n";
324 Value *CurrentValue =
nullptr;
325 for (
auto const &
E : Spills) {
326 if (CurrentValue !=
E.def()) {
327 CurrentValue =
E.def();
328 CurrentValue->
dump();
341 struct PaddingCalculator {
344 unsigned StructSize = 0;
351 void addType(
Type *Ty) {
353 if ((StructSize & (TyAlign - 1)) != 0)
354 StructSize =
alignTo(StructSize, TyAlign);
360 for (
auto *Ty : Types)
364 unsigned computePadding(
Type *Ty,
unsigned ForcedAlignment) {
366 auto Natural =
alignTo(StructSize, TyAlign);
367 auto Forced =
alignTo(StructSize, ForcedAlignment);
370 if (Natural != Forced)
371 return std::max(Natural, Forced) - StructSize;
378 ArrayType *getPaddingType(
Type *Ty,
unsigned ForcedAlignment) {
379 if (
auto Padding = computePadding(Ty, ForcedAlignment))
399 PaddingCalculator Padder(C, DL);
401 Name.append(
".Frame");
411 auto *FnPtrTy = FnTy->getPointerTo();
415 Type *PromiseType = PromiseAlloca
424 assert(PromiseAlloca ==
nullptr &&
"lowering doesn't support promises");
427 Value *CurrentDef =
nullptr;
429 Padder.addTypes(Types);
432 for (
auto &S : Spills) {
433 if (CurrentDef == S.def())
436 CurrentDef = S.def();
438 if (CurrentDef == PromiseAlloca)
443 if (
auto *AI = dyn_cast<AllocaInst>(CurrentDef)) {
444 Ty = AI->getAllocatedType();
445 if (
unsigned AllocaAlignment = AI->getAlignment()) {
448 if (
auto PaddingTy = Padder.getPaddingType(Ty, AllocaAlignment)) {
450 Padder.addType(PaddingTy);
453 if (
auto *CI = dyn_cast<ConstantInt>(AI->getArraySize()))
454 Count = CI->getValue().getZExtValue();
460 S.setFieldIndex(Types.
size());
479 = (Layout.getTypeAllocSize(FrameTy) <=
Id->getStorageSize() &&
480 Layout.getABITypeAlignment(FrameTy) <=
Id->getStorageAlignment());
513 void visitStoreInst(
StoreInst &
SI) { PI.setAborted(&SI); }
517 void visitInstruction(
Instruction &I) { PI.setAborted(&I); }
527 AllocaUseVisitor Visitor(DL, DT, CB);
528 auto PtrI = Visitor.visitPtr(A);
529 if (PtrI.isEscaped() || PtrI.isAborted()) {
530 auto *PointerEscapingInstr = PtrI.getEscapingInst()
531 ? PtrI.getEscapingInst()
532 : PtrI.getAbortingInst();
533 if (PointerEscapingInstr) {
535 dbgs() <<
"AllocaInst copy was triggered by instruction: " 536 << *PointerEscapingInstr <<
"\n");
593 cast<Instruction>(Builder.CreateBitCast(CB, FramePtrTy,
"FramePtr"));
596 Value *CurrentValue =
nullptr;
598 Value *CurrentReload =
nullptr;
624 if (
auto *AI = dyn_cast<AllocaInst>(Orig)) {
625 if (
auto *CI = dyn_cast<ConstantInt>(AI->getArraySize())) {
626 auto Count = CI->getValue().getZExtValue();
635 return Builder.CreateInBoundsGEP(FrameTy, FramePtr, Indices);
640 auto CreateReload = [&](
Instruction *InsertBefore) {
641 assert(Index != InvalidFieldIndex &&
"accessing unassigned field number");
642 Builder.SetInsertPoint(InsertBefore);
644 auto *
G = GetFramePointer(Index, CurrentValue);
645 G->setName(CurrentValue->getName() +
Twine(
".reload.addr"));
647 return isa<AllocaInst>(CurrentValue)
649 : Builder.CreateLoad(FrameTy->getElementType(Index),
G,
650 CurrentValue->getName() +
Twine(
".reload"));
653 for (
auto const &
E : Spills) {
655 if (CurrentValue !=
E.def()) {
656 CurrentValue =
E.def();
657 CurrentBlock =
nullptr;
658 CurrentReload =
nullptr;
660 Index =
E.fieldIndex();
662 if (
auto *AI = dyn_cast<AllocaInst>(CurrentValue)) {
666 if (!AI->isStaticAlloca())
673 if (
auto Arg = dyn_cast<Argument>(CurrentValue)) {
677 InsertPt = FramePtr->getNextNode();
681 Arg->getParent()->removeParamAttr(
Arg->getArgNo(),
682 Attribute::NoCapture);
684 }
else if (
auto *II = dyn_cast<InvokeInst>(CurrentValue)) {
687 auto NewBB =
SplitEdge(II->getParent(), II->getNormalDest());
688 InsertPt = NewBB->getTerminator();
689 }
else if (isa<PHINode>(CurrentValue)) {
692 if (
auto *CSI = dyn_cast<CatchSwitchInst>(DefBlock->
getTerminator()))
696 }
else if (
auto CSI = dyn_cast<AnyCoroSuspendInst>(CurrentValue)) {
701 auto *
I = cast<Instruction>(
E.def());
702 assert(!
I->isTerminator() &&
"unexpected terminator");
705 if (DT.dominates(CB,
I)) {
706 InsertPt =
I->getNextNode();
710 InsertPt = FramePtr->getNextNode();
714 Builder.SetInsertPoint(InsertPt);
715 auto *
G = Builder.CreateConstInBoundsGEP2_32(
716 FrameTy, FramePtr, 0, Index,
717 CurrentValue->getName() +
Twine(
".spill.addr"));
718 Builder.CreateStore(CurrentValue,
G);
723 if (CurrentBlock !=
E.userBlock()) {
724 CurrentBlock =
E.userBlock();
731 if (
auto *PN = dyn_cast<PHINode>(
E.user())) {
732 assert(PN->getNumIncomingValues() == 1 &&
"unexpected number of incoming " 733 "values in the PHINode");
734 PN->replaceAllUsesWith(CurrentReload);
735 PN->eraseFromParent();
740 E.user()->replaceUsesOfWith(CurrentValue, CurrentReload);
743 BasicBlock *FramePtrBB = FramePtr->getParent();
752 bool MightNeedToCopy =
false;
755 for (
auto &
P : Allocas) {
757 UsersToUpdate.
clear();
759 auto *
I = cast<Instruction>(U);
760 if (DT.dominates(CB,
I))
763 MightNeedToCopy =
true;
765 if (!UsersToUpdate.
empty()) {
766 auto *
G = GetFramePointer(
P.second, A);
769 I->replaceUsesOfWith(A,
G);
776 if (MightNeedToCopy) {
777 Builder.SetInsertPoint(FramePtr->getNextNode());
779 for (
auto &
P : Allocas) {
784 "Coroutines cannot handle copying of array allocas yet");
786 auto *
G = GetFramePointer(
P.second, A);
787 auto *
Value = Builder.CreateLoad(A);
788 Builder.CreateStore(
Value,
G);
797 if (
auto *II = dyn_cast<InvokeInst>(TI))
798 II->setUnwindDest(Succ);
799 else if (
auto *CS = dyn_cast<CatchSwitchInst>(TI))
800 CS->setUnwindDest(Succ);
801 else if (
auto *CR = dyn_cast<CleanupReturnInst>(TI))
802 CR->setUnwindDest(Succ);
811 PHINode *LandingPadReplacement) {
818 if (LandingPadReplacement == PN)
829 assert(BBIdx != (
unsigned)-1 &&
"Invalid PHI Index!");
838 PHINode *LandingPadReplacement) {
840 if (!LandingPadReplacement && !PadInst->
isEHPad())
847 if (LandingPadReplacement) {
848 auto *NewLP = OriginalPad->
clone();
854 Value *ParentPad =
nullptr;
855 if (
auto *FuncletPad = dyn_cast<FuncletPadInst>(PadInst))
856 ParentPad = FuncletPad->getParentPad();
857 else if (
auto *CatchSwitch = dyn_cast<CatchSwitchInst>(PadInst))
858 ParentPad = CatchSwitch->getParentPad();
891 if ((LandingPad = dyn_cast_or_null<LandingPadInst>(BB.
getFirstNonPHI()))) {
905 IncomingBB->setName(BB.
getName() +
Twine(
".from.") + Pred->getName());
906 auto *PN = cast<PHINode>(&BB.
front());
908 int Index = PN->getBasicBlockIndex(IncomingBB);
909 Value *V = PN->getIncomingValue(Index);
912 &IncomingBB->
front());
914 PN->setIncomingValue(Index, InputV);
916 }
while (PN != ReplPHI);
931 if (
auto *PN = dyn_cast<PHINode>(&BB.front()))
932 if (PN->getNumIncomingValues() > 1)
942 return isa<CastInst>(&V) || isa<GetElementPtrInst>(&V) ||
943 isa<BinaryOperator>(&V) || isa<CmpInst>(&V) || isa<SelectInst>(&V);
949 return isa<CoroIdInst>(&
I) || isa<CoroSaveInst>(&I) ||
950 isa<CoroSuspendInst>(&
I);
961 for (
auto const &
E : Spills) {
963 if (CurrentDef !=
E.def()) {
964 CurrentDef = cast<Instruction>(
E.def());
965 CurrentBlock =
nullptr;
966 CurrentMaterialization =
nullptr;
970 if (CurrentBlock !=
E.userBlock()) {
971 CurrentBlock =
E.userBlock();
972 CurrentMaterialization = cast<Instruction>(CurrentDef)->clone();
978 if (
auto *PN = dyn_cast<PHINode>(
E.user())) {
979 assert(PN->getNumIncomingValues() == 1 &&
"unexpected number of incoming " 980 "values in the PHINode");
981 PN->replaceAllUsesWith(CurrentMaterialization);
982 PN->eraseFromParent();
988 E.user()->replaceUsesOfWith(CurrentDef, CurrentMaterialization);
996 if (&BB->front() ==
I) {
997 if (BB->getSinglePredecessor()) {
1002 return BB->splitBasicBlock(I, Name);
1013 return isa<AnyCoroSuspendInst>(BB->
front());
1025 if (!VisitedOrFreeBBs.
insert(From).second)
1048 if (
auto FI = dyn_cast<CoroAllocaFreeInst>(
User))
1049 VisitedOrFreeBBs.
insert(FI->getParent());
1058 unsigned depth = 3) {
1061 if (depth == 0)
return false;
1080 for (
auto U : AI->
users()) {
1096 for (
auto AI : LocalAllocas) {
1097 auto M = AI->getModule();
1102 Value *StackSave =
nullptr;
1111 for (
auto U : AI->users()) {
1113 if (isa<CoroAllocaGetInst>(U)) {
1114 U->replaceAllUsesWith(Alloca);
1120 auto FI = cast<CoroAllocaFreeInst>(U);
1128 DeadInsts.
push_back(cast<Instruction>(U));
1145 if (isa<CoroAllocaGetInst>(U)) {
1148 auto FI = cast<CoroAllocaFreeInst>(U);
1152 DeadInsts.
push_back(cast<Instruction>(U));
1159 return cast<Instruction>(Alloc);
1204 auto ValueBeforeCall = Builder.
CreateLoad(ValueTy, Alloca);
1210 if (isa<CallInst>(Call)) {
1213 auto Invoke = cast<InvokeInst>(Call);
1214 Builder.
SetInsertPoint(Invoke->getNormalDest()->getFirstNonPHIOrDbg());
1237 if (isa<LoadInst>(
User) || isa<StoreInst>(
User))
1241 auto Call = cast<Instruction>(
User);
1262 auto ArgTy = cast<PointerType>(Arg.
getType());
1263 auto ValueTy = ArgTy->getElementType();
1268 auto Alloca = Builder.
CreateAlloca(ValueTy, ArgTy->getAddressSpace());
1273 Builder.CreateStore(InitialValue, Alloca);
1282 Builder.SetInsertPoint(End);
1283 auto FinalValue = Builder.CreateLoad(ValueTy, Alloca);
1299 if (!
Arg.hasSwiftErrorAttr())
continue;
1308 if (!Alloca || !Alloca->isSwiftError())
continue;
1319 if (!AllocasToPromote.
empty()) {
1341 if (
auto *Save = CSI->getCoroSave())
1355 SuspendCrossingInfo Checker(F, Shape);
1362 for (
int Repeat = 0; Repeat < 4; ++Repeat) {
1366 for (
User *U :
I.users())
1367 if (Checker.isDefinitionAcrossSuspend(
I, U))
1368 Spills.emplace_back(&
I, U);
1381 for (
User *U : A.users())
1382 if (Checker.isDefinitionAcrossSuspend(A, U))
1383 Spills.emplace_back(&A, U);
1398 if (
auto AI = dyn_cast<CoroAllocaAllocInst>(&
I)) {
1412 for (
User *U : Alloc->users()) {
1413 if (Checker.isDefinitionAcrossSuspend(*Alloc, U))
1414 Spills.emplace_back(Alloc, U);
1420 if (isa<CoroAllocaGetInst>(
I)) {
1424 for (
User *U :
I.users())
1425 if (Checker.isDefinitionAcrossSuspend(
I, U)) {
1427 if (
I.getType()->isTokenTy())
1429 "token definition is separated from the use by a suspend point");
1430 Spills.emplace_back(&
I, U);
1438 for (
auto I : DeadInstructions)
1439 I->eraseFromParent();
auto lower_bound(R &&Range, T &&Value) -> decltype(adl_begin(Range))
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
static Instruction * splitBeforeCatchSwitch(CatchSwitchInst *CatchSwitch)
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
The "returned-continuation" lowering, where each suspend point creates a single continuation function...
A parsed version of the target data layout string in and methods for querying it. ...
reference emplace_back(ArgTypes &&... Args)
static bool localAllocaNeedsStackSave(CoroAllocaAllocInst *AI)
static IntegerType * getInt1Ty(LLVMContext &C)
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
This class represents an incoming formal argument to a Function.
AllocaInst * CreateAlloca(Type *Ty, unsigned AddrSpace, Value *ArraySize=nullptr, const Twine &Name="")
The "resume-switch" lowering, where there are separate resume and destroy functions that are shared b...
The "unique returned-continuation" lowering, where each suspend point creates a single continuation f...
CoroBeginInst * CoroBegin
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const char *Name)
Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of converting the string to 'bool...
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
void push_back(const T &Elt)
static Value * emitSetAndGetSwiftErrorValueAround(Instruction *Call, AllocaInst *Alloca, coro::Shape &Shape)
Set the swifterror value from the given alloca before a call, then put in back in the alloca afterwar...
static void updatePhiNodes(BasicBlock *DestBB, BasicBlock *OldPred, BasicBlock *NewPred, PHINode *LandingPadReplacement)
static void rewritePHIs(BasicBlock &BB)
SmallVector< CallInst *, 2 > SwiftErrorOps
static void setUnwindEdgeTo(Instruction *TI, BasicBlock *Succ)
LLVMContext & getContext() const
All values hold a context through their type.
static Value * emitGetSwiftErrorValue(IRBuilder<> &Builder, Type *ValueTy, coro::Shape &Shape)
Get the current swifterror value.
RetconLoweringStorage RetconLowering
static void dump(StringRef Title, SpillInfo const &Spills)
An instruction for reading from memory.
AllocaInst * PromiseAlloca
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...
This represents the llvm.coro.alloca.alloc instruction.
LLVMContext & getContext() const
Get the context in which this basic block lives.
bool isAllocaPromotable(const AllocaInst *AI)
Return true if this alloca is legal for promotion.
static const unsigned InvalidFieldIndex
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
iterator begin()
Instruction iterator methods.
BasicBlock * SplitEdge(BasicBlock *From, BasicBlock *To, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr)
Split the edge connecting specified block.
static Value * emitSetSwiftErrorValue(IRBuilder<> &Builder, Value *V, coro::Shape &Shape)
Set the given value as the current swifterror value.
void dump() const
Support for debugging, callable in GDB: V->dump()
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
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...
PointerType * getType() const
Overload to return most specific pointer type.
Class to represent struct types.
A Use represents the edge between a Value definition and its users.
static bool materializable(Instruction &V)
This represents the llvm.coro.alloca.free instruction.
PointerType * getPointerTo(unsigned AddrSpace=0) const
Return a pointer to the current type.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
static bool willLeaveFunctionImmediatelyAfter(BasicBlock *BB, unsigned depth=3)
After we split the coroutine, will the given basic block be along an obvious exit path for the resump...
void setName(const Twine &Name)
Change the name of the value.
This file provides a collection of visitors which walk the (instruction) uses of a pointer...
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
Instruction * clone() const
Create a copy of 'this' instruction that is identical in all ways except the following: ...
static void eliminateSwiftError(Function &F, coro::Shape &Shape)
Eliminate all problematic uses of swifterror arguments and allocas from the function.
User * getUser() const LLVM_READONLY
Returns the User that contains this Use.
A base class for visitors over the uses of a pointer value.
Type * getType() const
All values are typed, get the type of this value.
CoroIdInst * getSwitchCoroId() const
Value * emitAlloc(IRBuilder<> &Builder, Value *Size, CallGraph *CG) const
Allocate memory according to the rules of the active lowering.
Class to represent array types.
const BasicBlock * getSingleSuccessor() const
Return the successor of this block if it has a single successor.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
An instruction for storing to memory.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Value * getParentPad() const
AnyCoroIdRetconInst * getRetconCoroId() const
void setBody(ArrayRef< Type *> Elements, bool isPacked=false)
Specify a body for an opaque identified type.
void takeName(Value *V)
Transfer the name from V to this value.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Function * getDeclaration(Module *M, ID id, ArrayRef< Type *> Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block...
Class to represent pointers.
const BasicBlock & getEntryBlock() const
static void eliminateSwiftErrorAlloca(Function &F, AllocaInst *Alloca, coro::Shape &Shape)
Eliminate a formerly-swifterror alloca by inserting the get/set intrinsics and attempting to MemToReg...
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.
bool IsFrameInlineInStorage
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction...
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
static bool isSuspendBlock(BasicBlock *BB)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const Instruction & front() const
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
static bool isLocalAlloca(CoroAllocaAllocInst *AI)
Is the given alloca "local", i.e.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
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...
static Instruction * insertSpills(const SpillInfo &Spills, coro::Shape &Shape)
static Type * getVoidTy(LLVMContext &C)
This represents the llvm.coro.end instruction.
static bool isSuspendReachableFrom(BasicBlock *From, VisitedBlocksSet &VisitedOrFreeBBs)
Does control flow starting at the given block ever reach a suspend instruction before reaching a bloc...
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
static Instruction * lowerNonLocalAlloca(CoroAllocaAllocInst *AI, coro::Shape &Shape, SmallVectorImpl< Instruction *> &DeadInsts)
Turn the given coro.alloca.alloc call into a dynamic allocation.
static FunctionType * get(Type *Result, ArrayRef< Type *> Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Interval::pred_iterator pred_end(Interval *I)
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
AllocaInst * getPromiseAlloca() const
bool LowerDbgDeclare(Function &F)
Lowers llvm.dbg.declare intrinsics into appropriate set of llvm.dbg.value intrinsics.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
static bool isCoroutineStructureIntrinsic(Instruction &I)
void sort(IteratorTy Start, IteratorTy End)
SwitchLoweringStorage SwitchLowering
Iterator for intrusive lists based on ilist_node.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
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.
BlockVerifier::State From
void setIncomingBlock(unsigned i, BasicBlock *BB)
Align max(MaybeAlign Lhs, Align Rhs)
static CleanupPadInst * Create(Value *ParentPad, ArrayRef< Value *> Args=None, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
This struct is a compact representation of a valid (power of two) or undefined (0) alignment...
static void eliminateSwiftErrorArgument(Function &F, Argument &Arg, coro::Shape &Shape, SmallVectorImpl< AllocaInst *> &AllocasToPromote)
"Eliminate" a swifterror argument by reducing it to the alloca case and then loading and storing in t...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
bool dominates(const Instruction *Def, const Use &U) const
Return true if Def dominates a use in User.
unsigned getABITypeAlignment(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
void buildCoroutineFrame(Function &F, Shape &Shape)
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.
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...
void setAlignment(MaybeAlign Align)
unsigned Log2_64_Ceil(uint64_t Value)
Return the ceil log base 2 of the specified value, 64 if the value is zero.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
This class represents the llvm.coro.begin instruction.
A range adaptor for a pair of iterators.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
SmallVector< AnyCoroSuspendInst *, 4 > CoroSuspends
iterator_range< user_iterator > users()
IntegerType * getInt8Ty()
Fetch the type representing an 8-bit integer.
static BasicBlock * splitBlockIfNotFirst(Instruction *I, const Twine &Name)
void setSwiftError(bool V)
Specify whether this alloca is used to represent a swifterror.
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
static void rewriteMaterializableInstructions(IRBuilder<> &IRB, SpillInfo const &Spills)
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
const Function * getParent() const
static IntegerType * getInt32Ty(LLVMContext &C)
LLVM_NODISCARD bool empty() const
StringRef getName() const
Return a constant reference to the value's name.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
const Function * getParent() const
Return the enclosing method, or null if none.
static void lowerLocalAllocas(ArrayRef< CoroAllocaAllocInst *> LocalAllocas, SmallVectorImpl< Instruction *> &DeadInsts)
Turn each of the given local allocas into a normal (dynamic) alloca instruction.
void emitDealloc(IRBuilder<> &Builder, Value *Ptr, CallGraph *CG) const
Deallocate memory according to the rules of the active lowering.
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
size_type size() const
size - Returns the number of bits in this bitvector.
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value *> Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction.
SmallPtrSet< BasicBlock *, 8 > VisitedBlocksSet
bool isArrayAllocation() const
Return true if there is an allocation size parameter to the allocation instruction that is not 1...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
SmallVector< CoroEndInst *, 4 > CoroEnds
LLVM_NODISCARD char front() const
front - Get the first character in the string.
static BasicBlock * ehAwareSplitEdge(BasicBlock *BB, BasicBlock *Succ, LandingPadInst *OriginalPad, PHINode *LandingPadReplacement)
static StructType * buildFrameType(Function &F, coro::Shape &Shape, SpillInfo &Spills)
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
succ_range successors(Instruction *I)
static StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
static CleanupReturnInst * Create(Value *CleanupPad, BasicBlock *UnwindBB=nullptr, Instruction *InsertBefore=nullptr)
static const Function * getParent(const Value *V)
static bool mightWriteIntoAllocaPtr(AllocaInst &A, const DominatorTree &DT, const CoroBeginInst &CB)
void PromoteMemToReg(ArrayRef< AllocaInst *> Allocas, DominatorTree &DT, AssumptionCache *AC=nullptr)
Promote the specified list of alloca instructions into scalar registers, inserting PHI nodes as appro...
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
StringRef - Represent a constant reference to a string, i.e.
inst_range instructions(Function *F)
const Instruction * getFirstNonPHIOrDbg() const
Returns a pointer to the first instruction in this block that is not a PHINode or a debug intrinsic...
BasicBlock * AllocaSpillBlock
static void splitAround(Instruction *I, const Twine &Name)
static IntegerType * getInt8Ty(LLVMContext &C)
Type * getElementType() const
iterator_range< arg_iterator > args()
A wrapper class for inspecting calls to intrinsic functions.
const BasicBlock * getParent() const
an instruction to allocate memory on the stack